import React from 'react';

const ResultDisplay = ({ result }) => {
    if (!result) return <div className="result-display empty">请选择功能并执行请求</div>;

    if (result.type === 'error') {
        return (
            <div className="result-display error">
                <h3>请求失败</h3>
                <p>{result.data}</p>
            </div>
        );
    }

    return (
        <div className="result-display">
            <h3>{result.type === 'explain' ? '安全检测解释结果' : '死锁诊断结果'}</h3>
            <div className="result-content">
                {result.data.split('\n').map((line, i) => (
                    <p key={i}>{line}</p>
                ))}
            </div>

            <div className="input-summary">
                <h4>输入参数</h4>
                <p>进程数: {result.state.processCount}</p>
                <p>资源类型数: {result.state.resourceTypeCount}</p>
                {result.deadlockProcesses && (
                    <p>死锁进程: {result.deadlockProcesses.map(p => `P${p + 1}`).join(', ')}</p>
                )}
            </div>
        </div>
    );
};

export default ResultDisplay;